<!--
  #%L
  thinkbig-ui-feed-manager
  %%
  Copyright (C) 2017 ThinkBig Analytics
  %%
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  #L%
  -->
<vertical-section-layout section-title="类别定义" on-delete="vm.onDelete()" allow-delete="vm.canDelete()" is-delete-visible="vm.model.id != null" on-save-edit="vm.onSave()"
                         on-edit="vm.onEdit()" on-cancel-edit="vm.onCancel()" editable="vm.isEditable" allow-edit="vm.allowEdit" the-form="vm.categoryForm" is-valid="vm.isValid">
  <readonly-section>
    <div layout="row" class="layout-padding-top-bottom" flex>
      <span flex="25" class="property-name">类别名称</span>

      <div flex="25"> {{vm.model.name}}</div>
      <span flex="5"></span>
      <span flex="25" class="property-name">系统名称</span>

      <div flex>{{vm.model.systemName}}</div>
    </div>
    <div layout="row" class="layout-padding-top-bottom">
      <span flex="25" class="property-name">描述</span>

      <div flex>
        {{vm.model.description}}
      </div>
    </div>
    <div layout="row" class="layout-padding-top-bottom" ng-if="vm.securityGroupsEnabled == true">
      <span flex="25" class="property-name">Hadoop安全组</span>

      <div flex>
        {{vm.splitSecurityGroups()}}
      </div>
    </div>
    <div layout="row" class="layout-padding-top-bottom" layout-align="start start">
      <span flex="25" class="property-name">图标</span>

      <div layout="column">
        <ng-md-icon icon="{{vm.model.icon}}" ng-style="vm.getIconColorStyle(vm.model.iconColor)" style="margin:inherit" size="45"></ng-md-icon>
      </div>
    </div>
  </readonly-section>
  <editable-section>
    <ng-form name="vm.categoryForm">
      <div layout="row" flex="100">
        <md-input-container class="md-block" flex="40">
          <label>名称</label>
          <input name="categoryName" ng-model="vm.editModel.name" required/>

          <div ng-messages="vm.categoryForm.categoryName.$error" md-auto-hide="false">
            <div ng-message ="required">需要一个类别名称。</div>
            <div ng-message ="duplicateDisplayName">有一个现有的类别与该名称。</div>
            <div ng-message ="reservedCategoryName">该类别被保留。 请选择其他类别。</div>
          </div>
        </md-input-container>
        <div flex="10"></div>
        <md-input-container flex="40">
          <label>系统名称</label>

          <input id="systemName" name="systemName" ng-readonly="!vm.isSystemNameEditable() || vm.hasFeeds()" ng-model="vm.editModel.systemName" required/>

          <div class="hint">
            <span>{{vm.getSystemNameDescription()}}</span>
            <br>
            <a href="" ng-if="!vm.isSystemNameEditable() && vm.hasNoFeeds()" ng-click="vm.allowEditSystemName()">让我更改系统名称</a>
          </div>
          <div ng-messages="vm.categoryForm.systemName.$error" md-auto-hide="false">
            <div ng-message ="required">需要一个类别系统名称。</div>
             <div ng-message ="invalidName">无效，不能包含字母数字和下划线以外的其他字符。</div>
              <div ng-message ="duplicateSystemName">有一个现有的类别与该系统名称。</div>
              <div ng-message ="reservedCategoryName">该类别被保留。 请选择其他类别。</div>
          </div>
        </md-input-container>

      </div>

      <md-input-container class="md-block">
        <label>描述</label>
        <textarea ng-model="vm.editModel.description"></textarea>
      </md-input-container>

      <md-input-container class="md-block layout-padding-top-bottom flex-gt-sm condensed" flex-gt-sm="" style="" ng-if="vm.securityGroupsEnabled == true">
        <label class="label-small md-container-ignore">Hadoop Security Groups</label>
        <md-chips ng-model="vm.editModel.securityGroups" md-autocomplete-snap
                  md-transform-chip="vm.transformChip($chip)"
                  md-require-match="true" class="layout-padding-top-bottom">
          <md-autocomplete
              md-min-length="0"
              md-selected-item="vm.securityGroupChips.selectedItem"
              md-search-text="vm.securityGroupChips.searchText"
              md-items="item in vm.categorySecurityGroups.querySearch(vm.securityGroupChips.searchText)"
              md-item-text="item.name"
              md-no-cache="true"
              placeholder="Add a Hadoop Security Group">
            <span md-highlight-text="vm.securityGroupChips.searchText">{{item.name}}</span>
          </md-autocomplete>
          <md-chip-template>
                            <span>
                              <strong>{{$chip.name}}</strong>
                            </span>
          </md-chip-template>
        </md-chips>
      </md-input-container>

      <div layout="column">
        <div layout="row" layout-align="start start" class="layout-padding-top-bottom">
          <span class="md-input-label" style="font-size: 11px;" flex="25">图标 </span>
          <ng-md-icon icon="{{vm.editModel.icon}}" size="45" style="margin:inherit;" ng-style="vm.getIconColorStyle(vm.editModel.iconColor)"></ng-md-icon>
          <md-button class="md-primary" ng-click="vm.showIconPicker()" style="margin-left:35px;">替换图标</md-button>
        </div>
      </div>

      <thinkbig-property-list-editor properties="vm.editModel.userProperties" is-valid="vm.isValid" ng-if="vm.model.id == null"></thinkbig-property-list-editor>
    </ng-form>
  </editable-section>
</vertical-section-layout>

